<template>
	<view class="content">
		<!-- 使用组件 -->
		<HearderSearch></HearderSearch>
		<swiper class="Swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
			<swiper-item @click="go_goods_dedail(item.goods_id)" v-for="item in lunboList" :key="item.goods_id">
				<image class="swiperItem_img" :src="item.image_src" mode=""></image>
			</swiper-item>
		</swiper>
		<view class="navBox">
			<view v-for="(item, index) in navList" :key="index" class="navItem">
				<image :src="item.image_src" mode=""></image>
			</view>
		</view>
		<view class="floorBox">
			<view class="floorItem" v-for="(item, index) in floorList" :key="index">
				<view class="top_title">
					<image :src="item.floor_title.image_src" mode=""></image>
				</view>
				<view class="main">
					<navigator :url="item.product_list[0].url" class="bigbox">
						<image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="smallbox">
						<navigator :url="item_s.url" v-if="index_s != 0" :key="index_s" v-for="(item_s, index_s) in item.product_list" >
							<image :style="{width: item_s.image_width + 'rpx'}" :src="item_s.image_src" mode="widthFix"></image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import HearderSearch from '../../components/HearderSearch/HearderSearch.vue'
	import tabbar_tip_number from '../../mixins/tabbar_tip_number.js'
	export default {
		mixins: [tabbar_tip_number],
		data() {
			return {
				lunboList: [],
				navList: [],
				floorList: []
			}
		},
		onLoad() {
			this.get_lunboList_req();
			this.get_navs_req();
			this.get_floor_List_req()
		},
		methods: {
			async get_lunboList_req() {
				const res = await uni.$http.get('/api/public/v1/home/swiperdata');
				this.lunboList = res.data.message;
			},
			// 获取导航栏菜单
			async get_navs_req() {
				const res = await uni.$http.get('/api/public/v1/home/catitems');
				this.navList = res.data.message;
			},
			// 获取楼层数据列表
			async get_floor_List_req() {
				const res = await uni.$http.get('/api/public/v1/home/floordata');
				// 改造数据为数据添加url属性
				res.data.message.forEach((item) => {
					item.product_list.forEach((item2) => {
						item2.url = `../../subPageA/goods_list/goods_list?${item2.navigator_url.split('?')[1]}`
					})
				})
				this.floorList = res.data.message;
			},
			// 去商品详情页
			go_goods_dedail(my_id) {
				uni.navigateTo({
					url: `../../subPageA/goods_dedail/goods_dedail?id=${my_id}`
				})
			}
		},
		components: {
			HearderSearch
		}
	}
</script>

<style lang="scss">
	.Swiper {
		margin-top: 100rpx;
		.swiperItem_img {
			width: 100%;
			height: 100%;
		}
	}
	.navBox {
		width: 100%;
		display: flex;
		margin-top: 15rpx;
		.navItem {
			flex: 1;
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			align-items: center;
			image {
				width: 130rpx;
				height: 130rpx;
				margin-bottom: 10rpx;
			}
		}
	}
	.floorBox {
		margin-top: 30rpx;
		.floorItem {
			.top_title {
				image {
					width: 100%;
					height: 60rpx;
				}
			}
			.main {
				display: flex;
				padding: 20rpx;
				.smallbox {
					display: flex;
					justify-content: space-around;
					flex-wrap: wrap;
				}
			}
		}
	}
</style>
